<template>
    <div :class="prevent ? 'xj-fixmenu' : ''">
        <van-tabbar v-model="mactive">
            <van-tabbar-item v-for="(item, index) in menubar" @click="menuClick(item.url, item.purl, item.text)" :key="index">
                <span>{{ item.text }}</span>
                <template #icon="props">
                    <img :src="item.src" v-if="item.src ? true : false" width="20px" height="16px" />
                    <van-icon v-else :name="item.name" :color="item.color" />
                </template>
            </van-tabbar-item>
        </van-tabbar>
    </div>
</template>

<script>
import Cookies from 'js-cookie';
export default {
    props: ['menubar', 'prevent', 'cactive'],
    data() {
        return {
            mactive: 0
        };
    },
    methods: {
        menuClick(url, purl, text) {
            if (this.prevent) {
                return;
            }
            if (text == '购物车') {
                if (isWeixin()) {
                    let rst = Cookies.get('fronttoken');
                    if (rst == undefined) {
                        //如果没有有fronttoken,则提示登录
                        sessionStorage.setItem('loginflag', 1);
                        this.$refs.xjwxreglogincom.getData();
                        return;
                    }
                } else {
                    let rst = Cookies.get('fronttoken');
                    if (rst == undefined) {
                        this.$router.push({ name: 'my' });
                        return;
                    }
                }
            }
            if (url) {
                console.log(url);
                // location.href = url;
            }
            //this.$router.push({path:purl,query:{num:Math.floor(Math.random()*100)}});
            if (purl) {
                this.$router.push({ path: purl });
            } //用这个不能用to否则会跳转
        }
    },
    created() {
        this.mactive = this.cactive;
    }
};
</script>

<style lang="scss" scoped>
.xj-fixmenu {
    .van-tabbar--fixed {
        position: relative;
    }
}
</style>
